package com.financing.platform.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.financing.platform.dao.IActivitiesMollionsWealthDao;
import com.financing.platform.dao.IFpFundInfoDao;
import com.financing.platform.dao.IProjectDao;
import com.financing.platform.dto.ActivitesMollionsWealthDTO;
import com.financing.platform.dto.FpFundInfoDTO;
import com.financing.platform.dto.ProjectDTO;
import com.financing.platform.service.IActivitiesMollionsWealthService;
import com.financing.platform.util.DateUtil;

/**
 * 
 * @ClassName: ActivitiesMollionsWealthServiceImpl
 * @Description: 百万财富产品计划 
 * @author  qiye
 * @date 2015年1月20日 上午10:17:09
 *
 */
@Service("activitiesMollionsWealthServiceImpl")
public class ActivitiesMollionsWealthServiceImpl extends BaseServiceImpl implements IActivitiesMollionsWealthService {

	
	@Autowired
	private IActivitiesMollionsWealthDao activitiesMollionsWealthDaoImpl;
	
	@Autowired
	private IProjectDao projectDaoImpl;
	
    @Autowired
	private IFpFundInfoDao fpFundInfoDao;
	
	
	@Override
	public List<Map<String,Object>> queryActivitiesMollionsWealthList(
			ActivitesMollionsWealthDTO dto) throws Exception {
		List<Map<String,Object>> listRes = new ArrayList<Map<String,Object>>();
		List<ActivitesMollionsWealthDTO> list = activitiesMollionsWealthDaoImpl.queryActivitiesMollionsWealthProduct(dto);
		 for(ActivitesMollionsWealthDTO adto : list){
			 Map<String,Object> resMap = new HashMap<String,Object>();
				//如果目前在产品活动时间中返回状态1:活动产品有效 如果目前还未到活动时间返回状态2：未开始 否则返回3:已结束
				if(DateUtil.nowBetweenstartTimeAndendTime(adto.getBeginTime(), adto.getEndTime())){
					adto.setStatus(1); 
				}else if(DateUtil.nowBeforeStartTime(adto.getBeginTime())){
					adto.setStatus(2);
				}else{
					adto.setStatus(3);
				}
				resMap.put("activitiesMollionsWealth", adto);
				//pType为私募  查询私募
				if(!"01".equals(adto.getpType())){
					ProjectDTO project = new ProjectDTO();
					project.setId(adto.getpId());
					List<ProjectDTO>  viewList =  projectDaoImpl.getProjectList(project);
					resMap.put("product", viewList.size()<=0?null:viewList.get(0));
				}else{
					FpFundInfoDTO fundInfoDto=new FpFundInfoDTO();
					fundInfoDto.setId(adto.getpId());
					resMap.put("product",fpFundInfoDao.getFpFundInfo(fundInfoDto));
				}
				listRes.add(resMap);
		 }
		return listRes;
	}

	@Override
	public int addActivitiesMollionsWealthProduct(ActivitesMollionsWealthDTO dto)
			throws Exception {
		return activitiesMollionsWealthDaoImpl.addActivitiesMollionsWealthProduct(dto);
	}

	@Override
	public int updateActivitiesMollionsWealthProduct(
			ActivitesMollionsWealthDTO dto) throws Exception {
		return activitiesMollionsWealthDaoImpl.updateActivitiesMollionsWealthProduct(dto);
	}

	@Override
	public int queryActivitiesMollionsWealthCount(ActivitesMollionsWealthDTO dto)
			throws Exception {
		return activitiesMollionsWealthDaoImpl.queryActivitiesMollionsWealthProductCount(dto);
	}

	@Override
	public int deleteActivitiesMollionsWealthProduct(ActivitesMollionsWealthDTO dto)
			throws Exception {
		return activitiesMollionsWealthDaoImpl.deleteActivitiesMollionsWealthProduct(dto);
	}

}
